/*
 * @Description: tags数据
 * @Version: 2.0
 * @Autor: lhl
 * @Date: 2021-06-14 19:38:18
 * @LastEditors: lhl
 * @LastEditTime: 2021-06-14 20:10:13
 */
export default {
  state: {
    tagsList: []
  },
  mutations: {
    delTagsItem(state, data): void {
      state.tagsList.splice(data.index, 1)
    },
    setTagsItem(state, data): void {
      state.tagsList.push(data)
    },
    clearTags(state): void {
      state.tagsList = []
    },
    closeTagsOther(state, data): void {
      state.tagsList = data
    },
    closeCurrentTag(state, data): void {
      for (let i = 0, len = state.tagsList.length; i < len; i++) {
        const item = state.tagsList[i]
        if (item.path === data.$route.fullPath) {
          if (i < len - 1) {
            data.$router.push(state.tagsList[i + 1].path)
          } else if (i > 0) {
            data.$router.push(state.tagsList[i - 1].path)
          } else {
            data.$router.push('/')
          }
          state.tagsList.splice(i, 1)
          break
        }
      }
    }
  },
  getters: {
    tagsList: state => state.tagsList
  }
}
